import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

//  CupertinoActivityIndicator  指示器组件 应用示范
//void main(){
//  runApp(new CupertinoActivityIndicatorDemo());
//}

// CupertinoActivityIndicator  指示器组件
class CupertinoActivityIndicatorDemo extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
      title: "",
      home: new Scaffold(
        appBar: AppBar(
          title: Text("CupertinoActivityIndicator"),
          centerTitle: true,
        ),
        body: Center(
          child: CupertinoActivityIndicator(
            animating: true,
            radius: 40,
          )
        ),
      ),
    );
  }

}

//  CupertinoActivityIndicator  指示器组件 应用示范
//void main(){
//  runApp(new CupertinoAlertDialogDemo());
//}

// CupertinoAlertDialog  对话框组件
class CupertinoAlertDialogDemo extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
      title: "",
      home: new Scaffold(
        appBar: AppBar(
          title: Text("CupertinoAlertDialog  对话框组件"),
          centerTitle: true,
        ),
        body: Center(
          child: CupertinoAlertDialog(
            title: Text("提示"),
            content: SingleChildScrollView(
              child: ListBody(
                children: <Widget>[
                  Text("是否要删除？"),
                  Text("一旦删除就不可恢复")
                ],
              ),
            ),
            actions: <Widget>[
              CupertinoDialogAction(
                  child: Text("确定"),
                  onPressed: (){},
              ),
              CupertinoDialogAction(
                child: Text("取消"),
                onPressed: (){},
              ),
            ],
          ),
        ),
      ),
    );
  }

}


//  CupertinoButton  按钮组件 应用示范
//void main(){
//  runApp(new CupertinoButtonDemo());
//}

//  CupertinoButton  按钮组件
class CupertinoButtonDemo extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
      title: "",
      home: new Scaffold(
        appBar: AppBar(
          title: Text("CupertinoButton  按钮组件"),
          centerTitle: true,
        ),
        body: Center(
          child: CupertinoButton(
              child: Text("CupertinoButton"),
              color: Colors.blue,
              onPressed: (){}
              ),
        ),
      ),
    );
  }

}

//  Cupertino  导航组件 应用示范
void main(){
  runApp(new MyApp());
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
      title: "",
      theme: ThemeData.light(),
      home: new MyPage(),
    );
  }

}

class MyPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _MyPageState();
  }

}

class _MyPageState extends State<MyPage>{
  @override
  Widget build(BuildContext context) {
    // 最外层导航选项卡
    return CupertinoTabScaffold(
        //底部选项卡
        tabBar: CupertinoTabBar(
            //选项卡背景色
            backgroundColor: CupertinoColors.lightBackgroundGray,
            items: [
              //选项卡项：包含图标及文字
              BottomNavigationBarItem(
                  title: Text("主页"),
                  icon: Icon(CupertinoIcons.home)
              ),
              BottomNavigationBarItem(
                  title: Text("聊天"),
                  icon: Icon(CupertinoIcons.conversation_bubble)
              ),
            ],
        ),
        tabBuilder: (context,index){
          //选项卡绑定的视图
          return CupertinoTabView(
            builder: (context){
              switch(index){
                case 0:
                  return HomePage();
                case 1:
                  return ChatPage();
                default:
                  return Container();
              }
            },
          );
        });
  }

}

//主页
class HomePage extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    //基本布局结构：包含内容和导航栏
    return CupertinoPageScaffold(
        navigationBar: CupertinoNavigationBar(
          //导航栏只包含中部标题部分
          middle: Text("主页"),
        ),
        child: Center(
          child: Text(
            "主页",
            style: Theme.of(context).textTheme.button,
          ),
        )
    );
  }

}

// 聊天页面
class ChatPage extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
        navigationBar: CupertinoNavigationBar(
          middle: Text("聊天面板"),
          // 右边按钮
          trailing: Icon(CupertinoIcons.add),
          // 左边按钮
          leading: Icon(CupertinoIcons.back),
        ),
        child: Center(
          child: Text(
            "聊天面板",
            style: Theme.of(context).textTheme.button,
          ),
        )
    );
  }

}
